﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Reborn_WorldServer.App1AppHandler;
using App1AppHandler;
using Reborn_WorldServer;

namespace Reborn_Server.App1AppHandler
{
    public class Potion_PermStat30 : IConsumable
    {
        public bool MeetsConsumeRequirements(Character myCharacter, Loot lootitem)
        {
            bool meetsRequirements = false;
            string message = "";
            if (lootitem.Name.Contains("Strength"))
            {
                if (myCharacter.Strength < 22)
                    message = "Your Strength is to low for this potion";
                else if (myCharacter.Strength >= 32)
                    message = "Your Strength is to high for this potion";
                else
                    meetsRequirements = true;
            }
            if (lootitem.Name.Contains("Intelligence"))
            {
                if (myCharacter.Intelligence < 22)
                    message = "Your Intelligence is to low for this potion";
                else if (myCharacter.Intelligence >= 32)
                    message = "Your Intelligence is to high for this potion";
                else
                    meetsRequirements = true;
            }
            if (lootitem.Name.Contains("Wisdom"))
            {
                if (myCharacter.Wisdom < 22)
                    message = "Your Wisdom is to low for this potion";
                else if (myCharacter.Wisdom >= 32)
                    message = "Your Wisdom is to high for this potion";
                else
                    meetsRequirements = true;
            }
            if (lootitem.Name.Contains("Agility"))
            {
                if (myCharacter.Agility < 22)
                    message = "Your Agility is to low for this potion";
                else if (myCharacter.Agility >= 32)
                    message = "Your Agility is to high for this potion";
                else
                    meetsRequirements = true;
            }
            if (lootitem.Name.Contains("Dexterity"))
            {
                if (myCharacter.Dexterity < 22)
                    message = "Your Dexterity is to low for this potion";
                else if (myCharacter.Dexterity >= 32)
                    message = "Your Dexterity is to high for this potion";
                else
                    meetsRequirements = true;
            }

            if (meetsRequirements == false)
            {
                myCharacter.PlaySound("Ding", myCharacter.MapX, myCharacter.MapY);
                myCharacter.SendMessage(message, "server");
            }

            return meetsRequirements;
        }

        public void Consume(Character myCharacter, Loot lootitem)
        {
            LockItem lockItem = Managers.GameHandler.GetLockItem(myCharacter.MapID, myCharacter.Instance);
            lock (lockItem.LockObj)
            {
                //Map CurrentMap = Managers.GameHandler.GetMap(myCharacter.MapID, myCharacter.Instance);

                //List<Character> CharactersWithin4 = new List<Character>();
                foreach (MapItem mapitem in myCharacter.currentMapItem.mapItemsWithin8)
                {
                    if (Math.Abs(mapitem.MapX - myCharacter.MapX) <= 8 && Math.Abs(mapitem.MapY - myCharacter.MapY) <= 8)
                    {
                        foreach (CreatureBase creaturebase in mapitem.CreaturesBases)
                        {
                            if (creaturebase is Character)
                            {
                                Character character = (Character)creaturebase;
                                character.PlaySound("DrinkBottle", myCharacter.MapX, myCharacter.MapY);
                            }
                        }
                    }
                    //if (Math.Abs(mapitem.MapX - myCharacter.MapX) <= 4 && Math.Abs(mapitem.MapY - myCharacter.MapY) <= 4)
                    //{
                    //    foreach (CreatureBase creaturebase in mapitem.CreaturesBases)
                    //    {
                    //        if (creaturebase is Character)
                    //            CharactersWithin4.Add((Character)creaturebase);
                    //    }
                    //}
                }

                bool updateCharacter = false;
                if (lootitem.Name.Contains("Strength") && myCharacter.Strength < 32)
                {
                    myCharacter.Strength = myCharacter.Strength + 1;
                    updateCharacter = true;
                }
                if (lootitem.Name.Contains("Intelligence") && myCharacter.Intelligence < 32)
                {
                    myCharacter.Intelligence = myCharacter.Intelligence + 1;
                    updateCharacter = true;
                }
                if (lootitem.Name.Contains("Wisdom") && myCharacter.Wisdom < 32)
                {
                    myCharacter.Wisdom = myCharacter.Wisdom + 1;
                    updateCharacter = true;
                }
                if (lootitem.Name.Contains("Agility") && myCharacter.Agility < 32)
                {
                    myCharacter.Agility = myCharacter.Agility + 1;
                    updateCharacter = true;
                }
                if (lootitem.Name.Contains("Dexterity") && myCharacter.Dexterity < 32)
                {
                    myCharacter.Dexterity = myCharacter.Dexterity + 1;
                    updateCharacter = true;
                }
                if (updateCharacter == true)
                    myCharacter.Update_Character();
            }
        }
    }
}
